package com.zzjc.web.controller;

import com.zzjc.web.entity.Alarm;
import com.zzjc.web.service.AlarmService;
import com.zzjc.web.util.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/alarm")
@Api(tags = "警报管理")
public class AlarmController {

    @Autowired
    private AlarmService alarmService;

    @PostMapping("/addAlarm")
    @ApiOperation("添加警报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "摄像头id", required = true),
            @ApiImplicitParam(name = "points", value = "点位", required = true),
            @ApiImplicitParam(name = "area", value = "坐标", required = true),
            @ApiImplicitParam(name = "level", value = "警报等级", required = false)
    })
    public ApiResponse addAlarm(@RequestParam(value = "deviceId", required = true) String deviceId,
                                @RequestParam(value = "points", required = false) String points,
                                @RequestParam(value = "area", required = false) String area,
                                @RequestParam(value = "level", required = false) Integer level) {
        Alarm alarm = new Alarm();
        alarm.setDeviceId(deviceId);
        alarm.setPoints(points);
        alarm.setArea(area);
        alarm.setAlarmLevel(level);
        return alarmService.addAlarm(alarm);
    }

    @PostMapping("/listAlarm")
    @ApiOperation("查询警报信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "摄像头id", required = false),
            @ApiImplicitParam(name = "status", value = "状态：0-未处理 1-已处理", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true)
    })
    public ApiResponse getAllAlarms(@RequestParam(value = "deviceId", required = false) String deviceId,
                                    @RequestParam(value = "status", required = false) Integer status,
                                    @RequestParam(value = "pageNum", required = true) Integer pageNum,
                                    @RequestParam(value = "pageSize", required = true) Integer pageSize) {
        Alarm alarm = new Alarm();
        alarm.setDeviceId(deviceId);
        alarm.setStatus(status);
        alarm.setPageNum(pageNum);
        alarm.setPageSize(pageSize);
        return alarmService.getAllAlarms(alarm);
    }


    @PostMapping("/updateStatus")
    @ApiOperation("更新警报为已处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "alarmId", value = "警报id：传警报id，更新对应警报id为已处理；警报id置空，全部已处理", required = true)
    })
    public ApiResponse updateStatus(@RequestParam(value = "alarmId", required = true) String alarmId) {

        return alarmService.updateStatus(alarmId);
    }
}